<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('传输消息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse" style="display:none;">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>消息长度：</label>
                                <input type="text" name="msgSize"/>
                            </li>
                            <li>
                                <label>来源节点：</label>
                                <input type="text" name="fromNode"/>
                            </li>
                            <li>
                                <label>来源ID：</label>
                                <input type="text" name="fromId"/>
                            </li>
                            <li>
                                <label>消息校验码：</label>
                                <input type="text" name="msgMd5"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="transmission:msg:add">
                    <i class="fa fa-plus"></i> 发送消息
                </a>
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="transmission:msg:add">
                    <i class="fa fa-plus"></i> 发送文件
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="transmission:msg:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="transmission:msg:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="transmission:msg:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script src="../static/js/base64.min.js"  th:src="@{/js/base64.min.js}"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('transmission:msg:edit')}]];
        var removeFlag = [[${@permission.hasPermi('transmission:msg:remove')}]];
        var prefix = ctx + "transmission/msg";

        $(function() {
            var options = {
                url: prefix + "/listNodeMsg",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                downloadUrl: prefix ,
                modalName: "传输消息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'msgId',
                    title: '消息ID'
                },
                {
                    field: 'msgType',
                    title: '消息类型',
                    formatter: function(value, row, index) {
                        if(value == 0)
                            return '文本';
                        else if (value == 1)
                            return '文件';
                        else {
                            return '其他';
                        }
                    }
                },
                {
                    field: 'msgSize',
                    title: '消息字节长度'
                },
                {
                    field: 'fromNode',
                    title: '来源节点'
                },
                {
                    field: 'fromType',
                    title: '来源类型',
                    formatter: function(value, row, index) {
                        if(value == 0)
                            return '用户';
                        else if (value == 1)
                            return '业务系统';
                        else {
                            return '其他';
                        }
                    }
                },
                {
                    field: 'fromId',
                    title: '来源ID'
                },
                {
                    field: 'msgData',
                    title: '消息数据',
                    formatter: function(value, row, index) {
                        if(row.msgType == 1) {
                            if(!value.startsWith("/profile")) {
                                value = '/profile' + value;
                            }
                        }
                        return value;
                    }
                },
                {
                    field: 'createTime',
                    title: '发布时间'
                },
                {
                    field: 'msgMd5',
                    title: '消息校验码',
                    formatter: function(value, row, index) {
                        return Base64.encode(value);
                    },
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.msgId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.msgId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if(row.msgType == 1) {
                            link = row.msgData;
                            if(!link.startsWith("/profile")) {
                                link = '/profile' + link;
                            }
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="' + link  +'" ><i class="fa fa-edit"></i>下载</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>